package kr.hkit.androidcomplete03.ch28.common;

import java.util.ArrayList;

import kr.hkit.androidcomplete03.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

// Context 정보, ArrayList내용을 받아오기
public class MyAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	int layout;
	Context context;
	ArrayList<Item> lists;
	
	public MyAdapter(Context context, int layout, ArrayList<Item> arLists){
		this.context = context;
		this.layout = layout;
		this.lists = arLists;
		inflater = (LayoutInflater) context 
				 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

	}
	
	@Override
	public int getCount() {
		return lists.size();
	}

	@Override
	public Object getItem(int position) {
		return lists.get(position).getItemName();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		// 전개
		if(convertView == null){
			convertView = inflater.inflate(R.layout.itemrow, parent, false);
		}
		TextView itemName = (TextView)convertView.findViewById(R.id.itemName);
		TextView itemMaker = (TextView)convertView.findViewById(R.id.makerName);
		TextView itemPrice = (TextView)convertView.findViewById(R.id.itemPrice);
		
		itemName.setText(lists.get(position).getItemName());
		itemMaker.setText(lists.get(position).getItemMaker());
		itemPrice.setText(String.valueOf(lists.get(position).getItemPrice()));
		
		return convertView;
	}

}
